package  
{
	import flash.text.StyleSheet;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import style.TextStyle;
	/**
	 * ...
	 * @author jun
	 */
	public class MMLabel extends MMInteractive 
	{
		protected var textField:TextField;
		protected var _textStyle:TextStyle ;
		
		protected var _styleSheet:StyleSheet;
		
		public function MMLabel(vTextStyle:TextStyle = null ) 
		{
			if(vTextStyle!=null)
				_textStyle = vTextStyle;
			else
				_textStyle = TextStyle.defaultTextStyle;
			init();
		}
		
		override public function regResource():void
		{
			super.regResource();
		}
		
		override public function onInit():void
		{
			super.onInit();
			textField = new TextField();
			textField.autoSize = TextFieldAutoSize.LEFT;
			if (textStyle.textFormat)
			{
				textField.defaultTextFormat = textStyle.textFormat;
			}
			if (textStyle.filter && textStyle.filter.length > 0 )
			{
				textField.filters = textStyle.filter;
			}
			textStyle = new TextStyle(null);
			if (_styleSheet)
			{
				textField.styleSheet = styleSheet;
			}
			addChild(textField);
			selectable = false;
		}
		
		override public function onHide():void
		{
			super.onHide();
		}
		
		override public function onShow():void
		{
			super.onShow();
		}
		
		override public function updateData():void
		{
			super.updateData();
			if (_textStyle.textFormat)
			{
				textField.setTextFormat(_textStyle.textFormat);
			}
			
		}
		
		public function set text(value:String):void
		{
			init();
			textField.text = value;
			update();
		}
		
		public function get text():String
		{
			init();
			return textField.text;
		}
		
		public function set htmlText(value:String):void
		{
			textField.htmlText = value;
		}
		
		public function get htmlText():String
		{
			return textField.htmlText;
		}
		
		public function set selectable(value:Boolean):void
		{
			textField.selectable = value;
		}
		
		public function get selectable():Boolean
		{
			return textField.selectable;
		}
		
		public function get styleSheet():StyleSheet { return _styleSheet; }
		
		public function set styleSheet(value:StyleSheet):void 
		{
			_styleSheet = value;
		}
		
		public function get textStyle():TextStyle { return _textStyle; }
		
		public function set textStyle(value:TextStyle):void 
		{
			_textStyle = value;
			
			if (_textStyle.filter)
			{
				if (textField.filters)
				{
					textField.filters = null;
				}
				textField.filters = _textStyle.filter;
			}else
			{
				if (textField.filters)
				{
					textField.filters = null;
				}
			}
			update();
		}
		
		public function getTextField():TextField
		{
			return textField;
		}
		
		public function get textHeight():Number
		{
			return textField.textHeight;
		}
		
		public function get textWidth():Number
		{
			return textField.textWidth;
		}
		
		override public function gc():void
		{
			
			//if (textField && textField.parent)
			//{
				//textField.parent.removeChild(textField);
			//}

			//textField = null;
			//_textStyle = null;
			//_styleSheet = null;
			super.gc();
		}
	}

}